package thread;

public class Demo201_GetName {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                //获取当前的类名
                String cName = Demo201_GetName.class.getName();
                //获取当前的方法名
                String mName = Thread.currentThread().getStackTrace()[1].getMethodName();
                //获取当前的线程名
                Thread thread1 = Thread.currentThread();
                String tName = thread1.getName();
                System.out.println("当前类名：" + cName + ",当前方法名：" + mName +",当前线程名:"+ tName);
            }
        },"牛批");
        //起动线程
        thread.start();
    }
}
